<?php

require_once "OPDatabase.php";
require_once 'Team.php';

class Player {
	
	/**
	* -------------------------------------------------------------------------
	*
	* 									Attributes
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Id of the player
	 * 
	 * @var int
	 */
	protected $id = null;
	
	/**
	* Team of the player
	*
	* @var Team
	*/
	public $team;
	
	/**
	 * -------------------------------------------------------------------------
	 * 
	 * 									Static
	 * 
	 * -------------------------------------------------------------------------
	 */
	
	/**
	* -------------------------------------------------------------------------
	* 									Constructeur
	* -------------------------------------------------------------------------
	*/
	
	/**
	* Static constructor creating a new Player with a random team
	*
	* @return Player
	*/
	public static function newWithRandomTeam(){
		$newPlayer	= new Player();
				
		$newPlayer->setTeam(OPDatabase::randomTeam());

		return $newPlayer;	
	
	}
	
	/**
	* -------------------------------------------------------------------------
	*
	* 									Dynamic
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	* -------------------------------------------------------------------------
	* 									Setters
	* -------------------------------------------------------------------------
	*/
	
	/**
	* Set player's id
	*
	* @param $id
	* @return Player
	*/
	public function setId($id) {
		$this->id = $id;
	
		return $this;
	
	}
	
	/**
	* Set player's team
	*
	* @param $team
	* @return Player
	*/
	public function setTeam($team) {
		$this->team = $team;
		
		return $this;
	
	}
	
	/**
	* -------------------------------------------------------------------------
	* 									Getters
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Return the id of the player
	 * 
	 * @return int
	 */
	public function id() {
		return $this->id;
		
	}
	
	/**
	* Return the team of the player
	*
	* @return string
	*/
	public function team() {
		return $this->team;
	
	}

	/**
	* -------------------------------------------------------------------------
	* 									Database
	* -------------------------------------------------------------------------
	*/
	
	public function save() {
		OPDatabase::savePlayer($this);
	
	}
	
}